package part07_组合模式_学校院系展示;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: College
 * @Author: AllenSun
 * @Date: 2020/3/2 20:43
 */
public class College extends OrganizationComponent {

    List<OrganizationComponent> organizationComponents=new ArrayList<OrganizationComponent>();

    //构造器
    public College(String name, String des) {
        super(name, des);
    }

    //重写add方法
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        //将来实际业务中，College的add方法和University的add方法不一定完全相等
        organizationComponents.add(organizationComponent);
    }

    //重写remove方法
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    @Override
    protected void print() {
        System.out.println("----------------"+getName()+"----------------");
        //遍历
        for (OrganizationComponent organizationComponent : organizationComponents) {
            organizationComponent.print();
        }
    }
}
